package com.dux.commons.scripts.java.url;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import com.dux.commons.scripts.java.ScriptClassLoader;


/**
 * 这是一个URL连接类，指定的脚本连接，用于{@link org.openaion.commons.scripting.impl.javacompiler.ScriptCompilerImpl}二进制数据加载.<br>
 * <br>
 * TODO: 实现 {@link URLConnection} 的所有方法，以确保有效的行为
 * 
 * @author SoulKeeper
 */
public class VirtualClassURLConnnection extends URLConnection 
{
	private InputStream is;
	
	
	/**
	 * 创建一个URL连接
	 * @param url
	 * 				类名的URL表示
	 * @param cl
	 * 				脚本加载器
	 */
	protected VirtualClassURLConnnection(URL url, ScriptClassLoader cl)
	{
		super(url);
		
		is = new ByteArrayInputStream(cl.getByteCode(url.getHost()));
	}
	
	
	/**
	 * 该方法忽略
	 */
	@Override
	public void connect() throws IOException 
	{

	}
	
	
	@Override
	public InputStream getInputStream() throws IOException
	{
		return is;
	}

}
